<template>
  <div style="height: 100%;">
    <el-form :model="queryParams" label-position="right" inline ref="queryRef" v-show="showSearch" @submit.prevent>
      <el-form-item :label="$t('d.cameraName')" prop="cameraName">
        <el-input v-model.number="queryParams.cameraName" />
      </el-form-item>
      <el-form-item :label="$t('d.productId')" prop="productId">
        <el-input v-model.number="queryParams.productId" />
      </el-form-item>
      <el-form-item :label="$t('d.result')" prop="result">
        <el-select v-model="queryParams.result" clearable>
          <el-option v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictLabel"
            :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('d.timeRange')">
        <el-date-picker v-model="dateRangeAddTime" type="datetimerange" :start-placeholder="$t('d.startTime')"
          :end-placeholder="$t('d.endTime')" value-format="YYYY-MM-DD HH:mm:ss" :default-time="defaultTime"
          :shortcuts="dateOptions">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button icon="search" type="primary" @click="handleQuery">{{ $t('btn.search') }}</el-button>
        <el-button icon="refresh" @click="resetQuery">{{ $t('btn.reset') }}</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" v-loading="loading" ref="table" border header-cell-class-name="el-table-header-cell"
      highlight-current-row @sort-change="sortChange">
      <el-table-column prop="id" :label="$t('cameraTable.id')" align="center" width="60" />
      <el-table-column prop="lineCode" :label="$t('cameraTable.lineCode')" align="center" />
      <el-table-column prop="cameraName" :label="$t('cameraTable.cameraName')" align="center" />
      <el-table-column prop="productId" :label="$t('cameraTable.productId')" align="center" />
      <el-table-column prop="testingContent" :label="$t('cameraTable.testingContent')" align="center" />
      <el-table-column prop="detectionResult" :label="$t('cameraTable.detectionResult')" align="center" />
      <el-table-column prop="standard" :label="$t('cameraTable.standard')" align="center" />
      <el-table-column prop="result" :label="$t('cameraTable.result')" align="center" />
      <el-table-column prop="createTime" :label="$t('cameraTable.createTime')" align="center" />
    </el-table>
    <pagination :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script setup name="CameraDetection">
import { listCameraDetection
 } 
from '@/api/business/cameradetection'
const { proxy } = getCurrentInstance()
const loading = ref(false)
const showSearch = ref(true)
const dateRangeAddTime = ref([])

const queryParams = reactive({
  cameraName:'',
  productId:'',
  result: undefined,
  pageNum: 1,
  pageSize: 10,
  sort: '',
  sortType: 'asc',
})
const total = ref(0)
const dataList = ref([])
const queryRef = ref()
const defaultTime = ref([new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)])

function getList(){
  proxy.addDateRange(queryParams, dateRangeAddTime.value, 'AddTime')
  loading.value = true
  listCameraDetection(queryParams).then(res => {
    const { code, data } = res
    if (code == 200) {
      dataList.value = data.result
      total.value = data.totalNum
      loading.value = false
    }
  })
}

// 查询
function handleQuery() {
  queryParams.pageNum = 1
  getList()
}
// 状态数据字典
const statusOptions = ref([])
proxy.getDicts('product_result').then((response) => {
  statusOptions.value = response.data
})
// 重置查询操作
function resetQuery(){
  proxy.resetForm("queryRef")
  handleQuery()
}
// 自定义排序
function sortChange(column) {
  var sort = undefined
  var sortType = undefined

  if (column.prop != null && column.order != null) {
    sort = column.prop
    sortType = column.order

  }
  queryParams.sort = sort
  queryParams.sortType = sortType
  handleQuery()
}
 handleQuery()
</script>